﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/AdminMaster.master" AutoEventWireup="true" CodeFile="PaymentInvoice.aspx.cs" Inherits="Admin_PaymentInvoice" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        /*Calendar Control CSS*/
        .cal_Theme1 .ajax__calendar_container   {
        background-color: #ffffff ; /*#DEF1F4;*/
        border:solid 1px #77D5F7;
        width:20em;  
        position   : absolute;   
        }        

        .cal_Theme1 .ajax__calendar_header  {
        /*background-color: #ffffff;*/
        margin-bottom: 4px;
        }
        .cal_Theme1 .ajax__calendar_title,
        .cal_Theme1 .ajax__calendar_next,
        .cal_Theme1 .ajax__calendar_prev    {
        color: #004080;
        padding-top: 3px;
        }

        .cal_Theme1 .ajax__calendar_body    {
        /*background-color: #ffffff;*/
        border: solid 1px #77D5F7;
        width:18em;
        height:15em;
        }

        .cal_Theme1 .ajax__calendar_dayname {
        text-align:center;
        font-weight:bold;
        margin-bottom: 4px;
        margin-top: 2px;
        color: #004080;
        }

        .cal_Theme1 .ajax__calendar_day {
        color: #004080;
        text-align:center;
        }
        .cal_Theme1 .ajax__calendar_hover .ajax__calendar_day,
        .cal_Theme1 .ajax__calendar_hover .ajax__calendar_month,
        .cal_Theme1 .ajax__calendar_hover .ajax__calendar_year,
        .cal_Theme1 .ajax__calendar_active  {
        color: #004080;
        font-weight: bold;
        /*background-color: #DEF1F4;*/
        }

        .cal_Theme1 .ajax__calendar_today   {
        font-weight:bold;
        }

        .cal_Theme1 .ajax__calendar_other,
        .cal_Theme1 .ajax__calendar_hover .ajax__calendar_today,
        .cal_Theme1 .ajax__calendar_hover .ajax__calendar_title {
        color: #bbbbbb;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script>
        function calendarShown(sender, args) {
            sender._popupBehavior._element.style.zIndex = 10005;
        }
    </script>

    <script type="text/javascript" lang="javascript">

        function Validate(sender, args) {
            var gridView = document.getElementById("<%=gvPaymentInvoice.ClientID %>");
            var checkBoxes = gridView.getElementsByTagName("input");
            if (checkBoxes != undefined) {
                for (var i = 0; i < checkBoxes.length; i++) {
                    if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) {
                        args.IsValid = true;
                        return;
                    }
                }
                args.IsValid = false;
            }
            else {
                args.IsValid = true;
                return;
            }
        }
        //////////////////////////////////////
        function checkAll(objRef, type) {

            if (type == 'H') {
                var GridView = objRef.parentNode.parentNode.parentNode;
                var inputList = GridView.getElementsByTagName("input");
                for (var i = 0; i < inputList.length; i++) {
                    var row = inputList[i].parentNode.parentNode;
                    if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                        if (objRef.checked) {
                            inputList[i].checked = true;
                        }
                        else {
                            inputList[i].checked = false;
                        }
                    }
                }
            }
            if (type == 'I') {
                var row = objRef.parentNode.parentNode;
                var GridView = row.parentNode;
                var inputList = GridView.getElementsByTagName("input");

                if (objRef.checked == false) {
                    var CA = $('#ContentPlaceHolder1_gvPaymentInvoice_checkAll');
                    CA[0].checked = false;
                }
            }
            CheckAmount();
        }
        function CheckAmount() {
            var GridView = document.getElementById("<%=gvPaymentInvoice.ClientID %>");
            var inputList = GridView.getElementsByTagName("input");
            var mount = 0.00;
            for (var i = 0; i < inputList.length; i++) {
                var row = inputList[i].parentNode.parentNode;
                if (i > 0) {
                    if (inputList[i].type == "checkbox") {
                        if (inputList[i].checked) {
                            var InvoiceAmount = GridView.rows[i].cells[3].innerText;
                            mount = mount + parseFloat(InvoiceAmount, 10);
                        }
                    }
                }
            }
            var AMT = $('#<%=txtAmount.ClientID%>');
            AMT.val(mount.toFixed(2));
        }
        function InvoiceDate(date) {

            var re = /^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$/;

            if (date.value != '') {
                $('#<%=lblDtError.ClientID%>').html("");
                if (re.test(date.value)) {
                    $('#<%=lblDtError.ClientID%>').html("");
                    return true;
                }
                else {
                    $('#<%=lblDtError.ClientID%>').html("Date must be mm/dd/yyyy format");
                    return false;
                }
            }
            else {
                $('#<%=lblDtError.ClientID%>').html("");
            }
            //onblur="CheckAmount(this)"
        }
    </script>
    <asp:ScriptManager ID="ScriptID" runat="server"></asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table>
                <tbody>
                    <tr>
                        <td colspan="2" style="text-align: left;">
                            <h2>Assessor Payment</h2>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 50%; text-align: right">Role Type &nbsp;<font color="red">*</font>&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                        <td style="width: 50%;">
                            <asp:DropDownList ID="ddlRoalType" runat="server" OnSelectedIndexChanged="ddlRoalType_SelectedIndexChanged" AutoPostBack="True" Width="220px">
                            </asp:DropDownList>
                            &nbsp;<asp:RequiredFieldValidator ID="reqRoalType" Display="Dynamic" InitialValue="0" ForeColor="red" ControlToValidate="ddlRoalType" runat="server" ErrorMessage="Select Role Type"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 50%; text-align: right">Payee Name &nbsp;<font color="red">*</font>&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                        <td style="width: 50%;">
                            <asp:DropDownList ID="ddlUserName" runat="server" Width="220px" OnSelectedIndexChanged="ddlUserName_SelectedIndexChanged" AutoPostBack="True">
                            </asp:DropDownList>
                            &nbsp;<asp:RequiredFieldValidator ID="reqUserName" Display="Dynamic" InitialValue="0" ForeColor="red" ControlToValidate="ddlUserName" runat="server" ErrorMessage="Select Payee Name"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" colspan="2" style="height: 30px; text-align: center">

                            <asp:Label ID="lblMessage" runat="server" Font-Bold="True"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: left;">
                            <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select at least one Invoice." Display="Dynamic"
                                ClientValidationFunction="Validate" ForeColor="Red"></asp:CustomValidator>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: left;">
                            <div class="grd_table" style="overflow-x: auto; width: 950px; margin-left: 05px;">
                                <asp:GridView ID="gvPaymentInvoice" runat="server" PageSize="10" AllowPaging="true" Width="100%" DataKeyNames="InvoiceID"
                                    AutoGenerateColumns="false" OnSelectedIndexChanged="gvPaymentInvoice_SelectedIndexChanged" OnPageIndexChanging="gvPaymentInvoice_OnPageIndexChanging">
                                    <EmptyDataRowStyle ForeColor="Red" HorizontalAlign="Center" />
                                    <EmptyDataTemplate>
                                        No Invoices found for selected Role and selected Payee.  
                                    </EmptyDataTemplate>
                                    <Columns>
                                        <asp:TemplateField ItemStyle-HorizontalAlign="center">
                                            <HeaderTemplate>
                                                <div style="margin: 5px;">
                                                    <asp:CheckBox ID="checkAll" runat="server" Text="" TextAlign="Right" onclick="checkAll(this,'H');" />
                                                </div>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox type="checkbox" runat="server" ID="chkIsActive" EnableViewState="true" onclick="checkAll(this,'I');" />
                                                <%--<input type="checkbox" runat="server"  id="chkIsActive"  enableviewstate="true" />--%>
                                            </ItemTemplate>
                                            <ItemStyle Width="2%" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="InvoiceID" HeaderText="Invoice ID" Visible="false">
                                            <ItemStyle Width="5%" HorizontalAlign="Left" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="InvoiceNo" HeaderText="Invoice No.">
                                            <ItemStyle Width="20%" HorizontalAlign="Left" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="InvoiceDate" HeaderText="Invoice Date">
                                            <ItemStyle Width="20%" HorizontalAlign="Left" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="InvoiceAmount" HeaderText="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Invoice Amount">
                                            <ItemStyle Width="15%" HorizontalAlign="Right" />
                                            <HeaderStyle HorizontalAlign="Right" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="InvoiceComment" HeaderText="Comments">
                                            <ItemStyle Width="30%" HorizontalAlign="Left" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:BoundField>
                                        <asp:TemplateField HeaderText="Download" ItemStyle-Width="10%">
                                            <ItemTemplate>
                                                <asp:HyperLink runat="server" NavigateUrl='<%#GetInvoiceReceipt(Eval("InvoicePath"))%> '
                                                    Text='Download'></asp:HyperLink>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <%--<asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="InvoicePath" runat="server" CausesValidation="false" CommandName="Edit"
                                            CommandArgument='<%# Eval("InvoiceID") %>'>Download</asp:LinkButton>
                                    </ItemTemplate>
                                    <ItemStyle Width="15%" />
                                </asp:TemplateField>--%>
                                    </Columns>
                                </asp:GridView>

                            </div>
                        </td>

                    </tr>
                    <tr runat="server" id="PD1">
                        <td colspan="2" style="text-align: center;">
                            <h4>Payment Details</h4>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: left;"></td>
                    </tr>
                    <tr runat="server" id="PD2">
                        <td style="width: 50%; text-align: right">Amount &nbsp;<font color="red">*</font>&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                        <td style="width: 50%;">
                            <asp:TextBox ID="txtAmount" runat="server" Style="text-align: right" placeholder="Amount" Width="100px" MaxLength="50"></asp:TextBox>&nbsp;&nbsp;(GBP)
                        <asp:Label runat="server" Text="" ID="lblAmount"></asp:Label>
                            &nbsp;<asp:RequiredFieldValidator ID="reqAmount" runat="server" ControlToValidate="txtAmount" ForeColor="Red" Display="Dynamic" ErrorMessage="Enter Payment Amount."></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="regExpVal" runat="server" Display="Dynamic" ForeColor="Red" ValidationExpression="((\d+)((\.\d{1,2})?))$" ErrorMessage="Please enter valid amount upto 2 decimal places." ControlToValidate="txtAmount" />

                        </td>
                    </tr>
                    <tr runat="server" id="PD3">
                        <td colspan="2" style="text-align: left;"></td>
                    </tr>
                    <tr runat="server" id="PD4">
                        <td style="width: 50%; text-align: right">Payment Date &nbsp;<font color="red">*</font>&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                        <td style="width: 50%;">
                            <%--    <asp:TextBox ID="txtInvoiceSDate" TextMode="Date" runat="server" Width="220px" MaxLength="50"></asp:TextBox>&nbsp; 
                    <asp:RequiredFieldValidator ID="reqInvoiceSDate" runat="server" ControlToValidate="txtInvoiceSDate" ForeColor="Red" ErrorMessage="Select Invoice Date."></asp:RequiredFieldValidator>--%>
                            <div class="controls input-append date form_date" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input1" data-link-format="yyyy-mm-dd">
                                <asp:TextBox ID="txtInvoiceSDate" runat="server" MaxLength="50" placeholder="" ViewStateMode="Enabled" Width="100px"
                                    cultureinvariantvalues="true" onblur="InvoiceDate(this)"></asp:TextBox>

                                <asp:CalendarExtender ID="mdlStartDate" runat="server" Format="dd/MM/yyyy" PopupButtonID="popcalender1" OnClientShown="calendarShown" TargetControlID="txtInvoiceSDate" CssClass="cal_Theme1" FirstDayOfWeek="Monday" />
                                <i class="icon-th" id="popcalender1"></i>
                                <asp:RequiredFieldValidator runat="server" ID="rfvDate" ControlToValidate="txtInvoiceSDate" Display="Dynamic"
                                    ErrorMessage="Please select Payment Date" ForeColor="Red"></asp:RequiredFieldValidator>
                                <asp:Label runat="server" ID="lblDtError" Text="" ForeColor="Red" Visible="true"></asp:Label>
                            </div>

                        </td>

                    </tr>
                    <tr runat="server" id="PD5">
                        <td colspan="2" style="text-align: left;"></td>
                    </tr>
                    <tr runat="server" id="PD6">
                        <td style="width: 50%; text-align: right">Comments&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                        <td style="width: 50%;">
                            <asp:TextBox ID="txtComment" TextMode="MultiLine" runat="server" placeholder="Enter Comments" Width="220px" MaxLength="50"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: left;"></td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: left;"></td>
                    </tr>
                    <tr runat="server" id="PD7">

                        <td></td>
                        <td style="padding-left: 8%;">
                            <asp:Button ID="btnSave" runat="server" SkinID="buttonSkin" Text="Paid" OnClick="btnSave_Click" />
                            &nbsp; &nbsp;</td>

                    </tr>

                </tbody>
            </table>
            <table width="100%">
                <tr><td align="center"><h2>Paid Invoices</h2></td></tr>
                <tr>
                    <td><asp:GridView ID="gvPayedInvoice" runat="server" AllowPaging="True" Width="100%" DataKeyNames="InvoiceID"
                                    AutoGenerateColumns="False" OnSelectedIndexChanged="gvPayedInvoice_SelectedIndexChanged" OnPageIndexChanging="gvPayedInvoice_OnPageIndexChanging">
                                    <EmptyDataRowStyle ForeColor="Red" HorizontalAlign="Center" />
                                    <EmptyDataTemplate>
                                        No Invoices found for selected Role and selected Payee.  
                                    </EmptyDataTemplate>
                                    <Columns>
                                        <asp:BoundField DataField="InvoiceID" HeaderText="Invoice ID" Visible="false">
                                            <ItemStyle Width="5%" HorizontalAlign="Left" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="InvoiceNo" HeaderText="Invoice No.">
                                            <ItemStyle Width="20%" HorizontalAlign="Left" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="InvoiceDate" HeaderText="Invoice Date">
                                            <ItemStyle Width="20%" HorizontalAlign="Left" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="InvoiceAmount" HeaderText="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Invoice Amount">
                                            <ItemStyle Width="15%" HorizontalAlign="Right" />
                                            <HeaderStyle HorizontalAlign="Right" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="InvoiceComment" HeaderText="Comments">
                                            <ItemStyle Width="30%" HorizontalAlign="Left" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                        </asp:BoundField>
                                        <asp:TemplateField HeaderText="Download" ItemStyle-Width="10%">
                                            <ItemTemplate>
                                                <asp:HyperLink runat="server" NavigateUrl='<%#GetInvoiceReceipt(Eval("InvoicePath"))%> '
                                                    Text='Download'></asp:HyperLink>
                                            </ItemTemplate>
                                            <ItemStyle Width="10%" />
                                        </asp:TemplateField>
                                        <%--<asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="InvoicePath" runat="server" CausesValidation="false" CommandName="Edit"
                                            CommandArgument='<%# Eval("InvoiceID") %>'>Download</asp:LinkButton>
                                    </ItemTemplate>
                                    <ItemStyle Width="15%" />
                                </asp:TemplateField>--%>
                                        <asp:BoundField DataField="PaymentComment" HeaderText="Payment Comment" />
                                        <asp:BoundField DataField="PaymentDate" HeaderText="Payment Date" />
                                        <asp:BoundField DataField="PAYMENTAMOUNT" HeaderText="Payment Amount" />
                                    </Columns>
                                </asp:GridView></td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>

